package com.jh.concurrent.lock;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author JH_Wong
 * @projectName newforward
 * @title ReentrantLockDemo.java
 * @package com.jh.concurrent.lock
 * @description 重入锁测试类
 * @date 2019-05-16 22:48
 */
public class ReentrantLockDemo {

    private static int count = 0;

    private static ReentrantLock lock = new ReentrantLock();

    public static void incr() {
        lock.lock();
        try {
            Thread.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        count++;
        lock.unlock();
    }

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 1000; i++) {
            new Thread(ReentrantLockDemo::incr).start();
        }

        Thread.sleep(3000);
        System.out.println("count：" + count);
    }

}
